/**
 *
 */
package com.fita.webpay.entity;

import org.apache.commons.lang3.StringUtils;

import com.demo2do.core.utils.Alias;

/**
 * @author downpour
 *
 */
@Alias("PayChannel")
public enum PayChannel {
    
    // 微信公众号网页
    WECHATPAY("wechatpay"),
    
    // 微信小程序
    WEAPPPAY("weapppay"),
    
    // 支付宝
    ALIPAY("alipay"),
    
    // 瀚银商讯通 （银联标准）
    HANDPAY("handpay"),
    
    // 易宝银行卡
    YOPPAY("yoppay"),
    
    // 易宝微信
    YOPWECHAT("yopWechat"),
    
    // 易宝支付宝
    YOPALIPAY("yopAlipay"),;
    
    private String code;
    
    /**
     *
     * @param code
     */
    PayChannel(String code) {
        this.code = code;
    }

    /**
     * get pay channel by the code
     *
     * @param code
     * @return
     */
    public static PayChannel codeOf(String code) {
        for(PayChannel channel : PayChannel.values()) {
            if(StringUtils.equalsIgnoreCase(channel.getCode(), code)) {
                return channel;
            }
        }
        return null;
    }

    /**
     * whether pay channel supports code
     *
     * @param code
     * @return
     */
    public static boolean supports(String code) {
        return codeOf(code) != null;
    }

    /**
     *
     * @return
     */
    public boolean isAlipay() {
        return StringUtils.equalsIgnoreCase(this.getCode(), "alipay");
    }

    /**
     *
     * @return
     */
    public boolean isWechatpay() {
        return StringUtils.equalsIgnoreCase(this.getCode(), "wechatpay");
    }

    /**
     * @return the code
     */
    public String getCode() {
        return this.code;
    }

    /**
     *
     * @return
     */
    public String getName() {
        return this.name();
    }

    /**
     *
     * @return
     */
    public int getOrdinal() {
        return this.ordinal();
    }

}
